<%@ page contentType="application/pdf" %><%@ page import="java.util.*" %><%@ page import="com.ionglobal.misc.*" %><%@ page import="com.ionglobal.misc.*" %><%@ page import="com.dhec.ggs.*"%><%@ page import="java.io.*"%><%@ page import="com.lowagie.text.pdf.*" %><%@ include file="/inc/init_include.jsp" %><%@ page import="com.ionglobal.lib.*" %><%
Sysop sysop = new Sysop();
if (session.getAttribute("sysop")!=null) {
	sysop = (Sysop) session.getAttribute("sysop");
	System.out.println("sysop!");
} else {
	return;
}
		//禁止缓存
		//response.setHeader("Cache-Control","no-cache");
		//response.setHeader("Cache-Control","no-store");
		//response.setHeader("Expires","0");
		String link = Request.getString("link");
		int fileId = Request.getInt("fileId", 0);
		String p = Request.getString("p");
		boolean canPrint = p.equals("1");
		int dcn = Request.getInt("dcn", 0);
		int pic = Request.getInt("pic", 0);
		int hes = Request.getInt("hes", 0);
		int othid = Request.getInt("oth", 0);
		int tech = Request.getInt("tech", 0);
		int isDCN = Request.getInt("D", 0);//旧版扫描的设变PDF，使用阅读器打开
		String language = Request.getString("L");
		if(dcn>0){
			DesignChangeApp decApp=new DesignChangeApp();
			EngineerChangeNoticeApp ecApp = new EngineerChangeNoticeApp();
			DesignChange dec=new DesignChange();
			dec=decApp.getDesignChange(dbi,dcn);
			EngineerChangeNotice engNotic = ecApp.getEngineerChangeNoticeByDcnid(dbi, dcn);
			if(dec.getStatus()==40 && dec.getSurveyFile()!=null && dec.getSurveyFile().length()>0 && engNotic.getSummary().equals("调查发行"))
				link=dec.getSurveyFile(); //调查发行时可在搜索列表打开调查发行的合并PDF
			else
				link=dec.getFile();
		}
		if(pic>0){
			DrawingApp drawApp = new DrawingApp();
			Drawing draw = drawApp.getDrawing(dbi, pic);
			if(draw!=null)
				link = draw.getFile();
		}
		if(tech>0){
			TechNoticeApp techApp = new TechNoticeApp();
			TechNotice techNotice=new TechNotice();
			techNotice=techApp.getTechNotice(dbi,tech);
			link=techNotice.getFile();	
		}
		if(othid>0){
			OtherDataApp otherApp=new OtherDataApp();
			OtherData othData = otherApp.getOtherData(dbi, othid);
			if(othData!=null)
				link = othData.getFile();
		}
		if(hes>0){
			HesDataApp hesApp = new HesDataApp();
			HesData hesData = hesApp.getHesData(dbi, hes);
			if(hesData!=null)
				if(language.equals("E"))
					link = hesData.getFile();
				else if(language.equals("J"))
					link = hesData.getJFile();	
		}
		if(fileId>0){
			AttachmentApp attApp = new AttachmentApp();
			Attachment att = attApp.getAttachment(dbi, fileId);
			if(att!=null)
				link = att.getFilePath();	
		}
		if(link.startsWith("\\") || link.startsWith("/")){
			link=SysEnv.getFileRoot()+link.substring(1, link.length());
		}
		//if(isDCN==1){
			if(canPrint){
				//PdfEncryptor.encrypt(pdfRead,response.getOutputStream(),null,null,
				//PdfWriter.AllowAssembly|PdfWriter.AllowFillIn|PdfWriter.AllowScreenReaders|PdfWriter.AllowPrinting,true);
				File file = new File(link);
				java.io.OutputStream out1 = response.getOutputStream(); 
				java.io.InputStream in = new java.io.FileInputStream(file);
				BufferedOutputStream bo = new BufferedOutputStream(out1); 
				BufferedInputStream bi = new BufferedInputStream(in); 
				
				int bytesRead = 0; 
				byte[] buffer = new byte[8192]; 
				while ((bytesRead = bi.read(buffer, 0, 8192)) != -1) { 
					bo.write(buffer, 0, bytesRead); 
				} 
				bo.flush(); 
				bi.close(); 
				bo.close(); 
				in.close(); 
				out1.close();
			}else{
				PdfReader pdfRead = new PdfReader(link);
				//pdfRead.addViewerPreference(PdfName.HIDETOOLBAR, PdfBoolean.PDFTRUE);
				PdfEncryptor.encrypt(pdfRead,response.getOutputStream(),null,null,
				PdfWriter.AllowAssembly|PdfWriter.AllowFillIn|PdfWriter.AllowScreenReaders,true);
			}
		/*}else{
			File file = new File(link);
			java.io.OutputStream out1 = response.getOutputStream(); 
			java.io.InputStream in = new java.io.FileInputStream(file);
			BufferedOutputStream bo = new BufferedOutputStream(out1); 
			BufferedInputStream bi = new BufferedInputStream(in); 
			
			int bytesRead = 0; 
			byte[] buffer = new byte[81920]; 
			while ((bytesRead = bi.read(buffer, 0, 81920)) != -1) { 
				bo.write(buffer, 0, bytesRead); 
			} 
			bo.flush(); 
			bi.close(); 
			bo.close(); 
			in.close(); 
			out1.close();
		}*/
%><%@ include file="/inc/init_free.jsp" %>